//
//  LSZDetailsWithdrawalOrderVC.m
//  JKFuYinProject
//
//  Created by 九酷 on 2018/5/9.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LSZDetailsWithdrawalOrderVC.h"
#import <QuartzCore/QuartzCore.h>

@interface LSZDetailsWithdrawalOrderVC ()

@end

@implementation LSZDetailsWithdrawalOrderVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"订单详情";
    if(ScreenWidth ==414){
        cellHeight = 50;
    }else
    if(ScreenWidth ==375){
        cellHeight = 50;
    }else{
        cellHeight = 40;
    }
    [self.tableViewDetails registerClass:[LSZPayFootCell class] forHeaderFooterViewReuseIdentifier:@"LSZPayFootCell"];
    [self.tableViewDetails registerClass:[LSZStateTableViewCell class] forCellReuseIdentifier:@"LSZStateTableViewCell"];
    [self.tableViewDetails registerClass:[LSZWithdrawalTableViewCell class] forCellReuseIdentifier:@"LSZWithdrawalTableViewCell"];
    [self.tableViewDetails registerClass:[LSZWithdrawalFootView class] forHeaderFooterViewReuseIdentifier:@"LSZWithdrawalFootView"];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return cellHeight;
        }
        else if (indexPath.row == 1) {
            if(ScreenWidth ==414){
                return 130;
            }else
            if(ScreenWidth ==375){
                return 130;
            }else{
                return 120;
            }
        }else{
            return cellHeight;
        }
    }else{
        return cellHeight;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        return cellHeight;
    }else if (section == 2&&![self.withdrawalRecordMg.status isEqualToString:@"驳回"]){
        if (ScreenWidth == 320) {
            //5
            return 75;
        }else if(ScreenWidth == 375){
            // 6 7
            return 85;
        }else {
            //plus
            return 90;
        }
    }
    else{
        return 0.0001;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 15;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 4;
    }else if (section == 1){
        return 2;
    }
    else{
        return 1;
    }
}
-(void)clickSend
{
    NSLog(@"发送订单号给客服");

//需要发送给客服
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData *imageData = UIImageJPEGRepresentation(image, 0.5);//数值 0 - 1 之间
    image = [UIImage imageWithData:imageData];

    [self shareYaoQingMessageWithImageArray:@[image] type:SSDKPlatformSubTypeWechatSession];
//    [self shareImageAndTextToPlatformType:UMSocialPlatformType_WechatSession];
}
/*
#pragma mark - 分享图片
- (void)shareImageAndTextToPlatformType:(UMSocialPlatformType)platformType
{
//    UIGraphicsBeginImageContext(self.view.bounds.size);   //self为需要截屏的UI控件 即通过改变此参数可以截取特定的UI控件
//    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
//    UIImage *image= UIGraphicsGetImageFromCurrentImageContext();
//    UIGraphicsEndImageContext();


//     CGSize size = self.view.frame.size;
//    UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
//    CGRect rect = self.view.frame;
//    [self.view drawViewHierarchyInRect:rect afterScreenUpdates:YES];
//    UIImage * snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
//    UIGraphicsEndImageContext();


//    UIView * screenView = [[UIScreen mainScreen] snapshotViewAfterScreenUpdates:NO];
//    UIGraphicsBeginImageContextWithOptions(screenView.frame.size, YES, [[UIScreen mainScreen] scale]);
//    [screenView drawViewHierarchyInRect:screenView.bounds afterScreenUpdates:YES];
//    UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
//    UIGraphicsEndImageContext();

    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData *imageData = UIImageJPEGRepresentation(image, 0.5);//数值 0 - 1 之间
    image = [UIImage imageWithData:imageData];

    [self shareYaoQingMessageWithImageArray:@[image] type:SSDKPlatformSubTypeWechatSession];


//    NSLog(@"image:%@",image); //至此已拿到image
//    UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);//把图片保存在本地
    //创建分享消息对象
//    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
//    //创建图片内容对象
//    UMShareImageObject *shareObject = [[UMShareImageObject alloc] init];
//    __weak typeof(self) weakSelf = self;
//    [shareObject setShareImage:image];
//    //分享消息对象设置分享内容对象
//    messageObject.shareObject = shareObject;
//    //调用分享接口
//    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:weakSelf completion:^(id data, NSError *error) {
//        if (error) {
//            NSLog(@"************Share fail with error %@*********",error);
//            [weakSelf setStringWarning:@"分享失败!"];
//        }else{
//            NSLog(@"response data is %@",data);
//        }
//    }];;
}
*/
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        LSZWithdrawalFootView * foot = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"LSZWithdrawalFootView"];
        NSString * stringName = [NSString stringWithFormat:@"支付金额:%@福音值",self.withdrawalRecordMg.real_amount];
        NSMutableAttributedString * strName = [[NSMutableAttributedString alloc]initWithString:stringName];
        //设置：在0-3个单位长度内的内容显示成红色
        [strName addAttribute:NSForegroundColorAttributeName value:redUIColor range:NSMakeRange(5,stringName.length-5)];
         foot.labelOriginalPrice.attributedText = strName;
        foot.contentView.backgroundColor = [UIColor whiteColor];
        return foot;
    }else if (section == 2&&![self.withdrawalRecordMg.status isEqualToString:@"驳回"]){
        LSZPayFootCell * cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"LSZPayFootCell"];
        [cell.butSave setTitle:@"发送订单号给客服" forState:UIControlStateNormal];
        [cell.butSave addTarget:self action:@selector(clickSend) forControlEvents:UIControlEventTouchUpInside];
        return cell;
    }
    else{
        UITableViewHeaderFooterView * footView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"footView"];
        if (!footView) {
            footView = [[UITableViewHeaderFooterView alloc]initWithReuseIdentifier:@"footView"];
        }
        return footView;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row ==0&&indexPath.section == 0) {
        LSZStateTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZStateTableViewCell" forIndexPath:indexPath];
        cell.labelState.text = self.withdrawalRecordMg.status;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    else if (indexPath.row == 1&&indexPath.section == 0) {
        LSZWithdrawalTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZWithdrawalTableViewCell" forIndexPath:indexPath];
        cell.labelTitle.text = NSStr(self.withdrawalRecordMg.title);
        cell.labelTime.text = self.withdrawalRecordMg.uptime;
        if ([self.withdrawalRecordMg.via isEqualToString:@"微信"]) {
            cell.imageViewType.image = [UIImage imageNamed:@"微信提现"];
        }else if ([self.withdrawalRecordMg.via isEqualToString:@"支付宝"]){
            cell.imageViewType.image = [UIImage imageNamed:@"支付宝提现"];
        }
        else{
            cell.imageViewType.image = [UIImage imageNamed:@"手机充值"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellDetails"];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellDetails"];
        }
        if (indexPath.section == 0 && indexPath.row == 2) {
            cell.textLabel.textColor = titleColorLSZ;
            cell.textLabel.text = [NSString stringWithFormat:@"订单号:%@",self.withdrawalRecordMg.trade_no];
        }else if (indexPath.section ==0 && indexPath.row == 3){
             if ([self.withdrawalRecordMg.via isEqualToString:@"微信"]) {
                 cell.textLabel.text = [NSString stringWithFormat:@"微信钱包:%@ %@",self.withdrawalRecordMg.pay_to,self.withdrawalRecordMg.pay_name];
            }else if ([self.withdrawalRecordMg.via isEqualToString:@"支付宝"]){
                cell.textLabel.text = [NSString stringWithFormat:@"支付宝:%@ %@",self.withdrawalRecordMg.pay_to,self.withdrawalRecordMg.pay_name];
            }else{
                cell.textLabel.text = [NSString stringWithFormat:@"手机账号:%@ %@",self.withdrawalRecordMg.pay_to,self.withdrawalRecordMg.pay_name];
            }
            cell.textLabel.textColor = titleColorLSZ;
        }else if (indexPath.section == 1 && indexPath.row == 0){
            cell.textLabel.text = [NSString stringWithFormat:@"%@",self.withdrawalRecordMg.msg];//msg
            cell.textLabel.textColor = titleColorLSZ;
        }else{
            if (indexPath.section == 1 && indexPath.row == 1) {
                cell.textLabel.text = @"点击复制客服微信号:shengjing2019";
                cell.textLabel.textColor = redUIColor;
                [cell.textLabel tapGesture:^(UIGestureRecognizer *ges) {
                    [self goToFuZhi];
                }];
                [LSZSpecialPackaging addThreadWithOtherRGB:cell.contentView A:20 B:0 C:ScreenWidth-40 D:1 R:241 G:241 BB:241];
            }
            if(indexPath.section == 2 && indexPath.row == 0){
                cell.textLabel.text = @"点击拨打客服电话:18614972438";
                cell.textLabel.textColor = lightColor;
                [cell.textLabel tapGesture:^(UIGestureRecognizer *ges) {
                    [self telPhone];
                }];
            }
        }
        if(ScreenWidth ==414){
            cell.textLabel.font = FONT_17;
        }else
        if(ScreenWidth ==375){
            cell.textLabel.font = FONT_17;
        }else{
            cell.textLabel.font = FONT_14;
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1&& indexPath.row == 1) {
        [self goToFuZhi];
    }
    if (indexPath.section == 2&& indexPath.row == 0) {
        [self telPhone];
    }
}
-(void)goToFuZhi
{
    UIPasteboard * pastboard = [UIPasteboard generalPasteboard];
    pastboard.string = @"shengjing2019";
    [self setStringWarning:@"已复制到剪切板!"];
}
-(void)telPhone
{
    NSMutableString * string = [[NSMutableString alloc] initWithFormat:@"tel:%@",@"18614972438"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]];
}
-(UITableView *)tableViewDetails
{
    if (_tableViewDetails == nil) {
        _tableViewDetails  = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStyleGrouped];
        _tableViewDetails.delegate = self;
        _tableViewDetails.dataSource = self;
        _tableViewDetails.estimatedRowHeight =0;
        _tableViewDetails.estimatedSectionFooterHeight =0;
        _tableViewDetails.estimatedSectionHeaderHeight =0;
        _tableViewDetails.separatorColor = divider;
        _tableViewDetails.separatorInset = UIEdgeInsetsMake(0, 20, 0, 20);
        [self.view addSubview:_tableViewDetails];
    }
    return _tableViewDetails;
}
@end
